package com.czp.mall.order;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import com.czp.mall.config.RibbonConfig;
import com.czp.mall.order.config.ExcludeFromComponentScan;

@EnableEurekaClient
@SpringBootApplication
// @RibbonClient(name = "czp-mall-item", configuration = RibbonConfig.class)  // 指定自定义策略
// @ComponentScan(excludeFilters = { // 避免扫描被ExcludeFromComponentScan注释的类
//		@Filter(type = FilterType.ANNOTATION, classes = ExcludeFromComponentScan.class)}) 

@EnableCircuitBreaker // 开启断路器
@EnableHystrixDashboard
public class OrderServiceApplication {

	
	@Bean
	@LoadBalanced // Ribbon负载均衡，远程调用时自动负载均衡
	public RestTemplate restTemplate() {
		return new RestTemplate();
		// 使用httpclient
//		return new RestTemplate(new HttpComponentsClientHttpRequestFactory());
		// 使用okhttp
//		return new RestTemplate(new OkHttp3ClientHttpRequestFactory());
	}
	
	public static void main(String[] args) {
		SpringApplication.run(OrderServiceApplication.class, args);
	}
}
